/**
 * 
 */
package com.cmpanyandi.elearning.wordsdriller.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.cmpanyandi.elearning.utils.db.DbAdapter;
import com.cmpanyandi.elearning.wordsdriller.model.Configuration;

/**
 * Abstract activity form which provides DAO and state persistence.
 * 
 * @author wojtek
 * 
 */
public abstract class DictionaryActivityForm extends Activity {
    
    protected Long pk;
    protected TextView mainDescription;
    protected ImageView mainDictionaries;
    protected ImageView mainItemList;
    protected ImageView mainRepetition;
    protected static final Long unsavedPk = Long.valueOf(-1);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	mainDescription = (TextView) findViewById(R.id.mainDescription);
	mainDictionaries = (ImageView) findViewById(R.id.mainDictionaries);
	mainItemList = (ImageView) findViewById(R.id.mainItemList);
	mainRepetition = (ImageView) findViewById(R.id.mainRepetition);

	pk = savedInstanceState != null ? savedInstanceState.getLong(getStateProperty()) : null;
	if (pk == null) {
	    Bundle extras = getIntent().getExtras();
	    pk = extras != null ? extras.getLong(getStateProperty()) : unsavedPk;
	}
	registeMainDictionaryEvent();

    }

    private void registeMainDictionaryEvent() {
	mainDictionaries.setOnClickListener(new View.OnClickListener() {

	    @Override
	    public void onClick(View v) {
		Intent i = new Intent(v.getContext(), DictionaryList.class);
		startActivity(i);

	    }
	});
    }

    /**
     * Name of property to store state of activity.
     * 
     * @return name of state property
     */
    protected abstract String getStateProperty();
}
